package ru.nstu.isma.core.hsm;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * by Alexey Bessonov
 * Date: 24.10.13
 * Time: 23:33
 */
public class HMVariableTable {
    protected Map<String, HMVariable> variables = new HashMap<String, HMVariable>();

    public HMVariable get(String key) {
        return variables.get(key);
    }

    public boolean contain(String key) {
        return variables.containsKey(key);
    }

    public boolean empty() {
        return variables.size() == 0;
    }

    public void clear() {
        variables.clear();
    }

    public boolean add(HMVariable item) {
        if (contain(item.getCode())) {
            return false;
        }
        variables.put(item.getCode(), item);
        return true;
    }

    public boolean remove(String key) {
        if (!contain(key)) {
            return false;
        }
        variables.remove(key);
        return true;
    }

    public Set<String> keySet() {
        return variables.keySet();
    }
}
